<template>
  <div>
    <div class="h60">
      <span class="exnum">{{ Num }}.{{ item.title }}</span>
      <span class="labels">
        <span v-if="item.isJt == '1'">机经</span>
        <span v-if="item.isJt !== '1'" style="background: #7cc3d6">练习题</span>
        <span
          style="background: #ff5e4e"
          v-if="item.labelStyle == 'wrong-color'"
          >错题</span
        >
        <span style="background: #13bfbf" v-if="item.isYc == '1'"
          >本周预测</span
        >
        <span style="background: #94d0f7">{{ item.titleNumber }}</span>
      </span>
    </div>

    <!-- 阅读填空区域 -->
    <el-form>
      <div class="fill-in-blank" v-if="item.option&&item.content">
        <span v-for="(item, index) in content" :key="index"
          >{{ item }}
          <span v-if="index + 1 < content.length">
            <Select
              ref="Select"
              :options="options[index].split(',')"
              :isSub="isSub"
              v-if="!subFlag"
              @sendAnswer="getAnswer"
            ></Select>
          </span>
        </span>
      </div>

      <div v-else class="fill-in-blank">
        请检查此题是否完整
      </div>
    </el-form>
    <div class="time">
      <span>答题时间：{{ s_to_hs(answerTime) }}</span>
    </div>
  </div>
</template>

<script>
import Select from "../../../../practice/exercise/select/index";
import readingUtil from "@/utils/readingUtil";
export default {
  mixins: [readingUtil],
  props: ['item', 'Num'],
  components: {
    Select,
  },
  data () {
    return {
      answerTime: 0,
      subFlag: false, // 是否提交了答案
      options: [],
      isAnswerShow: false,
      iNum: '', // 题目索引号
      isSub: false,
      content: [],
      answerList: []
    }
  },
  created () {
    setInterval(this.countUpTime, 1000)
    // this.content=this.item.content.split('(PARAM)')

    // this.answerList
    // 回显答案
    if( this.item.answer){
      this.item.answer.split(',').forEach(ele => {
      this.answerList.push(ele)
    })
    }

  },
  mounted () {
    this.content = this.item.content.split('(PARAM)')
    this.options = this.item.option.split('&@#')

  },
  methods: {
    getAnswer (e) {
      // console.log(e);
      // console.log(this.$refs.Select.optionValue);
      let ary = []
      this.$refs.Select.forEach(item => {
        console.log(item.optionValue);
        if (!ary.includes(item.optionValue)) {
          ary.push(item.optionValue)
        }
      })
      console.log(ary);
      this.answerList = [...ary]

      let len = 0
      for (var i = 0; i < this.answerList.length; i++) {
        if (this.answerList[i] !== '') {
          len++
        }
      }
      if (len < this.$refs.Select.length) {
        this.$emit('nodone')
      } else {
        //  this.$emit('sendNum', this.answerList.length)
        this.$emit('sendAnswer', this.answerList.join(','))

      }
    },

  },
}
</script>

<style lang="less" scoped>
/deep/main .w1200 .wfd .h226[data-v-edf20660] .el-input__inner {
  height: 2.5rem;
  width: 10.25rem;
}
.fill-in-blank {
  font-size: 1.125rem;
  color: #666;
  line-height: 3.125rem;
  border: 0.1875rem dashed #ff5e4e;
  border-bottom: 0.1875rem dashed #ff5e4e !important;
  padding: 0 2.5rem;
  padding-top: 1.25rem;
  padding-bottom: 1.25rem;
  margin-top: 3.125rem;
  .el-select {
    width: 10.25rem;
    height: 2.5rem;
  }
  /deep/.el-input__inner {
    border-radius: 0;
    padding-left: 1.875rem;
  }
}
.wrong {
  border-color: #ff5e4e !important;
  color: #ff5e4e;
}
.right {
  border-color: #13bfbf !important;
  color: #13bfbf;
}
.h60 {
  height: 3.75rem;
  line-height: 3.75rem;
  padding-left: 1.25rem;
  box-sizing: border-box;
  background-color: #f7f7f7;
  display: flex;
  margin-bottom: 1rem;
  position: relative;
  .exnum {
    width: 45rem;
    font-size: 1rem;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .labels {
    display: flex;
    justify-content: flex-end;
    width: 21.25rem;
    span {
      height: 1.875rem;
      line-height: 1.875rem;
      padding: 0 0.375rem;
      box-sizing: border-box;
      background-color: #ff9b4f;
      border-radius: 0.1875rem;
      margin: 0.9375rem 0.46875rem;
      color: #fff;
      box-sizing: border-box;
    }
  }
}
.time {
  font-size: 1rem;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #333333;
  position: relative;
  margin-top: 1.875rem;
  span {
    margin-right: 1.875rem;
  }
  .iconfont {
    font-size: 1.5rem;
    color: #ccc;
  }
  .end {
    position: absolute;
    right: -1.5rem;
    text-align: right;
  }
}
</style>